<?php
require_once 'Zend/Db/Table/Abstract.php';
class MSA_Model_AdminUserInfo extends Zend_Db_Table_Abstract
{
	protected $_name = 'admin_user_info';
	
	
	public function selectUserInfo($uid)
	{
		//SQL:SELECT `A`.`name`, `A`.`email`, `A`.`id`, `B`.`username`, `B`.`last_login` FROM `admin_user_info` AS `A` INNER JOIN `admin_user` AS `B` ON B.id = A.user_id WHERE (user_id = 1)
		$query = $this->select()
						->from(array('A' => $this->_name), array('A.name', 'A.email', 'A.id'))
						->joinInner(array('B' => 'admin_user'), 'B.id = A.user_id', array('username' => 'B.username', 'last_login' => 'B.last_login'))
						->where('user_id = ?', $uid, Zend_Db::INT_TYPE);
		$query->setIntegrityCheck(false);//关闭检查
		$row = $this->fetchRow($query);
		if ($row) {
			return $row;
		}
		return false;
	}
	
	public function updateUserInfo($id, $data) 
	{
		$row = $this->find($id)->current();
		if ($row) {
			foreach ($data as $key => $value) {
				$row->$key = $value;
			}
			$updateId = $row->save();
			if ($updateId) {
				return true;
			}
		}
		return false;
	}
}